{% extends "base.html" %}
{% block title %}Model "{{model.name|escape}}"{% endblock %}
{% block head %}
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  <script type="text/javascript">
    var categories = [
      {% for category in model.categories %}
        "{{category}}",
      {% endfor %}
    ];
    $(function() {
      $("#search").click(function() {
        var q = $("#q");
        $.ajax({
          dataType: "jsonp",
          url: "http://search.twitter.com/search.json",
          data: {
            q: q.val(),
            rpp: 100,
          },
          success: function(msg) {
            table = $("#tweets");
            for(i = 0; i < msg.results.length; i++) {
              tweet = msg.results[i];
              row = $("<tr />");
              for(j = 0; j < categories.length; j++) {
                cell = $("<td />");
                cell.append($("<input />", {
                  type: "radio",
                  name: "tweet-category-" + i,
                  value: "category-" + j,
                }));
                row.append(cell);
              }
              cell = $("<td />", {
                text: tweet.text,
              })
              cell.append($("<input />", {
                type: "hidden",
                name: "tweet-text-" + i,
                value: tweet.text,
              }));
              cell.append($("<input />", {
                type: "hidden",
                name: "tweet-lang-" + i,
                value: tweet.iso_language_code,
              }));
              row.append(cell);
              table.append(row);
            }
          }
        })
      });
    });
  </script>
{% endblock %}
{% block body %}
  <h1>Model "{{model.name|escape}}"</h1>
  Search for: <input type="text" id="q" /><input type="button" value="Search" id="search" />
  <form method="POST" action="/model/{{model.key.id}}/train">
    <table id="tweets">
      <thead>
        {% for category in model.categories %}
          <th>{{category|escape}}</th>
        {% endfor %}
        <th>Text</th>
      </thead>
    </table>
    <input type="submit" value="Train" />
  </form>
{% endblock %}
